# Stage 1: Build React Application
FROM node:18 AS builder

WORKDIR /app

# Set timezone
ENV TZ="Asia/Shanghai"

## Update package index and install git
#RUN yum -y update && \
#    yum -y install git && \
#    yum clean all

# Clone GitHub project
RUN git clone https://github.com/365code365/react-plat.git .

RUN npm config set registry https://registry.npmmirror.com

# Install dependencies
RUN npm install -g npm@10.5.2 && \
    npm i --save-dev @types/jest --legacy-peer-deps && \
    npm install --legacy-peer-deps && \
    npm run build

# Stage 2: Build Nginx Server
FROM nginx:latest

# Copy the built React application to the default Nginx directory
COPY --from=builder /app/dist /usr/share/nginx/html

# Copy custom Nginx configuration file to the container
COPY config/nginx.conf /etc/nginx/nginx.conf

# Expose port
EXPOSE 80

# Start Nginx
CMD ["nginx", "-g", "daemon off;"]